import shutil

import numpy as np
import os
import shutil as sh

def gen_golden_data_simple():
    # np.random.uniform 生成一个随机数ndarray
    input_x = np.random.uniform(1, 100, [8, 3]).astype(np.float16)
    input_y = np.random.uniform(1, 100, [8, 3]).astype(np.float16)
    golden = (input_x + input_y).astype(np.float16)

    arr = np.array([])
    print(type(arr))  # <class 'numpy.ndarray'>
    print(type(input_x))  # <class 'numpy.ndarray'>

    print("input_x=\n", input_x)
    print("input_y=\n", input_y)
    print("golden=\n", golden)

    # 清空输入输出目录
    i = "./input"
    o = "./output"
    ix = os.path.join(i, "input_x.bin")
    iy = os.path.join(i, "input_y.bin")
    og = os.path.join(o, "golden.bin")
    try:
        if os.path.exists(i):
            shutil.rmtree(i)  # 删除文件夹下所有文件，文件夹不存在时报错，所以要先判断文件夹是否存在
        if os.path.exists(o):
            shutil.rmtree(o)
    except FileNotFoundError as e:
        print(e)

    # 创建输入输出空文件，文件夹和文件一起创建
    if not os.path.exists(i):
        os.makedirs(i)
    if not os.path.exists(o):
        os.makedirs(o)
    open(ix, "w").close()
    open(iy, "w").close()
    open(og, "w").close()


    input_x.tofile(ix)
    input_y.tofile(iy)
    golden.tofile(og)

if __name__ == "__main__":
    gen_golden_data_simple()